﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Newtonsoft.Json;
using YFTFunction;
using YFTOpenAPI;


namespace YY.Web.MyAgent
{
    public partial class PayDeposit : BaseFunction.LoginHelp
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                lbl_mobile.Value = base.GetSessionModel().mobile + "";
            }
        }
        /// <summary>
        /// 保证金支付
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSubmitPay_Click(object sender, EventArgs e)
        {
            var ip = BaseFunction.StaticTableClass.SystemConfigHelp.GetSystemConfigValue("YFT_IP");
            var key = ConfigurationManager.AppSettings["YYAgent"];
            var code = ldf_code.Value;
            var fund = txtFund.Text;
            var mobile = lbl_mobile.Value;
            /*位移加密参数*/
            string ecode = BaseFunction.DEncrypt.DEncrypt.Encrypt(code);
            string efund = BaseFunction.DEncrypt.DEncrypt.Encrypt(fund);
            string emoblie = BaseFunction.DEncrypt.DEncrypt.Encrypt(mobile);
            /*MD5加密*/
            var md5 =YFTOpenAPI.OpenAPI.MD5Encrypt(ecode + efund + emoblie,key);
            try
            {
                var result =
                    WebRequestHelp.PostDataToUrl("ecode" + ecode + "efund" + efund + "emoblie" + emoblie + "key" + key,
                        ip + "HTTP/YFTAPI.aspx");
                var requestInfo = JsonConvert.DeserializeObject<YFTOpenAPI.Model.ResponseData>(result);

                if (requestInfo.statuscode == 1)
                {
                    /*更新提交状态*/
                    var getModel = base.GetSessionModel();
                    getModel.is_submit = 1;
                    BaseFunction.StaticTableClass.agent_users_Help.bll_agent_users.Update(getModel);
                    BaseFunction.MessageBox.ParentJscriptMsg(this.Page, "保证金缴纳成功", "center.aspx");
                }
                else
                {
                    BaseFunction.MessageBox.Show(this.Page, "保证金缴纳失败:" + requestInfo.message);
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
    }
}